package me.jessyan.mvparms.demo.mvp.ui.activity.coupon;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import me.jessyan.mvparms.demo.R;
import me.jessyan.mvparms.demo.di.component.coupon.DaggerMyCouponComponent;
import me.jessyan.mvparms.demo.di.module.coupon.MyCouponModule;
import me.jessyan.mvparms.demo.mvp.contract.coupon.MyCouponContract;
import me.jessyan.mvparms.demo.mvp.presenter.coupon.MyCouponPresenter;
import me.jessyan.mvparms.demo.mvp.ui.adapter.FragBrandVpAdapter;
import me.jessyan.mvparms.demo.mvp.ui.adapter.MyCouponVpAdapter;
import me.jessyan.mvparms.demo.mvp.ui.widget.CustomToolbar;
import me.jessyan.mvparms.demo.mvp.ui.widget.SlideTabView;

import static com.jess.arms.utils.Preconditions.checkNotNull;

/**
 * 我的优惠券
 */
public class MyCouponActivity extends BaseActivity<MyCouponPresenter> implements MyCouponContract.View {

    @BindView(R.id.toolbar)
    CustomToolbar toolbar;
    @BindView(R.id.tab)
    SlideTabView slideTabView;
    @BindView(R.id.viewpager)
    ViewPager viewPager;
    private List<String> tabStrs;

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerMyCouponComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .myCouponModule(new MyCouponModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_my_coupon; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        toolbar.setListener(new CustomToolbar.ToolbarListener() {
            @Override
            public void onLeftBack() {
                killMyself();
            }

            @Override
            public void onRightBack() {

            }
        });
        initViewpager();
    }

    private void initViewpager() {
        tabStrs = new ArrayList<>();
        tabStrs.add("未使用");
        tabStrs.add("已使用");
        tabStrs.add("已过期");

        MyCouponVpAdapter adapter = new MyCouponVpAdapter(R.layout.item_frag_brand_vp, tabStrs, getApplicationContext());
        viewPager.setOffscreenPageLimit(1);
        viewPager.setAdapter(adapter);
        slideTabView.initTab(tabStrs, viewPager);

        adapter.setListener(new MyCouponVpAdapter.MyCouponVpAdapterListener<Boolean>() {
            @Override
            public void getItem(View view, int type, Boolean data) {
                if(type==0){
                    Intent intent = new Intent(MyCouponActivity.this,CouponDetailActivity.class);

                    intent.putExtra("type",data?CouponDetailActivity.COUPON_SPECIAL:CouponDetailActivity.COUPON_GENERAL);
                    intent.putExtra("isPastDue",false);
                    startActivity(intent);
                }else if (type==1){
                    Intent intent = new Intent(MyCouponActivity.this,CouponDetailActivity.class);
                    intent.putExtra("type",data?CouponDetailActivity.COUPON_SPECIAL:CouponDetailActivity.COUPON_GENERAL);
                    intent.putExtra("isPastDue",true);
                    startActivity(intent);
                }else {
                    Intent intent = new Intent(MyCouponActivity.this,CouponDetailActivity.class);
                    intent.putExtra("type",CouponDetailActivity.COUPON_PARKING);
                    intent.putExtra("isPastDue",true);
                    startActivity(intent);
                }
            }
        });
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }


}
